#pragma once

#include <sys/time.h>
#include <sys/epoll.h>
#include <pthread.h>
#include <netinet/in.h>
#include <atomic>
#include <string>
#include <functional>

#include <pthread.h>
#include <assert.h>

#include "Socket.h"
using namespace std;

class Thread {
public:
	typedef function <int()> ThreadFunc;
	explicit Thread(const ThreadFunc &f, const string &name);

	~Thread(){};

	void start();
	int join();

	bool started() const {
		return _started;
	} 
	pid_t pid() const {
		return _pid;
	} 
	pthread_t tid() const {
		return _tid;
	}
	const string &name() const {
		return _name;
	}
//	virtual int runInThread();
private:
	ThreadFunc _funcInThread;
	pid_t _pid;
	pthread_t _tid;
	string _name;
	bool _started;

	static void *startRoutine(void *thread);
};

class TcpThread : public Thread{
public:
	typedef function <int()> ThreadFunc;
	explicit TcpThread(const ThreadFunc &f, const string &name);
//	int runInThread();
	void setEpollFd(int fd){_epfd = fd;}
	int getEpollFd(){return _epfd;}
private:
	int _epfd;
};


